﻿/*----------------------------------------------------------------
            // Copyright (C) 济南确信软件技术有限公司
            // 版权所有。 
            //
            // 文件名：DataHelper
            // 文件功能描述：
            //
            // 
            // 创建标识：2013-12-12   梁晋
            ///
            // 修改标识：
            // 修改描述：            
　----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace BpmHsjqYw.Common
{
    public class DataHelper
    {
        #region DataTable转Json
        /// <summary>
        /// DataTable转Json
        /// </summary>
        /// <param name="_dt"></param>
        /// <returns></returns>
        public static string ToDataGrid(DataTable _dt)
        {
            string GridJson = "{\"total\":" + _dt.Rows.Count + ",\"rows\":[";
            for (int i = 0; i < _dt.Rows.Count; i++)
            {
                GridJson += "{";
                string strTemp = "";
                for (int j = 0; j < _dt.Columns.Count; j++)
                {
                    strTemp = (j == _dt.Columns.Count - 1 ? "" : ",");
                    GridJson += "\"" + _dt.Columns[j].ColumnName.ToString() + "\":\"" + _dt.Rows[i][j].ToString() + "\"" + strTemp;
                }
                strTemp = (i == _dt.Rows.Count - 1 ? "}" : "},");
                GridJson += strTemp;
            }
            GridJson += "]}";
            return GridJson;
        }
        #endregion
        #region 获取guid
        /// <summary>
        /// 获取guid
        /// </summary>
        /// <returns>guid</returns>
        public string  GetGuid()
        {
            string strGuid = Guid.NewGuid().ToString();
            return strGuid;
        }
        #endregion
    }
}
